/*
 * BufferFrame.hpp
 *
 *  Created on: May 2, 2012
 *      Author: Ka Wai Lo
 */

#ifndef BUFFERFRAME_HPP_
#define BUFFERFRAME_HPP_

const unsigned PAGE_SIZE_OFFSET = 12;
const unsigned PAGE_SIZE = 4096; // = 2 ^ PAGE_SIZE_OFFSET. Must be multiple of 4096

class BufferFrame {
public:
	// ==== Constructor + Rule of 3 ====
	BufferFrame(const int vecId); // Default constructor
	virtual ~BufferFrame(); // Destructor
	BufferFrame(BufferFrame& o); // Copy constructor * No const because copied object will update original object
	BufferFrame& operator=(BufferFrame& o); // Assignment operator * No const

	// ==== Other public methods ====
	void init(int c_file);
	void* getData(); // Get the pointer for read & write
	unsigned getPageId();
	int getVecId();
	bool isAlloc();
	bool isDirty();
	void setDirty();
	void mapPage(const unsigned pageId, const unsigned size);
	void freePage();
	unsigned size();

private:
	bool bCopy; // Copy of a base BufferFrame. i.e. don't free() at destructor
	BufferFrame* oParent;
	void* pPageBuffer;
	void* pFileBuffer;
	int fd;
	unsigned iPageSize;
	unsigned iPageId;
	unsigned iVecId;
	bool bAlloc;
	bool bDirty;
};

#endif /* BUFFERFRAME_HPP_ */
